<?php

class sbDan {

    const AgentId = '700902';
    const AgentPassword = 'trat';

    public function connect() {
        $xml = file_get_contents("http://azusdex.webcopo.com/travis/lib/model/hotel.xml", true);
        
        $encoded = urlencode($xml);
        $string = "requestType=2&sentData=$encoded";

        $headers = array(
            "Content-Type: application/x-www-form-urlencoded;charset=UTF-8;",
            "Cache-Control: no-cache",
            "Pragma: no-cache",
            "Content-length: " . strlen($string),
        );

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_URL, sbValues::URL_DAN);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
//        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $string); 
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $response = curl_exec($ch);
        $error = curl_errno($ch);
        curl_close($ch);

        var_dump('response: '.$response);
        var_dumP('error: '.$error);
        return $response;
    }
    
    public function testConnection() {
        $url = 'http://azusdex.webcopo.com/FriendlyGuard/web/frontend_dev.php/ninit';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        
        $response = curl_exec($ch);
        $error = curl_errno($ch);
        curl_close($ch);

        var_dump('response: '.$response);
        var_dumP('error: '.$error);
    }

}
